<template>
  <div class="body-content">
    <PageTable ref="defaultTable"
               action="/user-center/app/findPage"
               :columns="columns">
    </PageTable>
  </div>
</template>
<script lang="ts" setup>

// @ts-ignore
import {getCurrentInstance, markRaw, ref} from "vue";
// @ts-ignore
import {ElMessageBox} from "element-plus/es";
// @ts-ignore
const {proxy} = getCurrentInstance()
// @ts-ignore
import {Delete} from '@element-plus/icons-vue'

const authority = proxy.$authority;
const defaultTable = ref<any>(null)
const columns: any = [{
  title: '应用名称',
  field: 'appName',
  select: true
}, {
  title: '应用识别名',
  field: 'appLabel',
  select: true
}, {
  title: '应用类型',
  field: 'appType',
  select: true,
  formatter: {
    type: 'dict',
    dictType: 'app_type'
  }
},
  {
    title: '应用范围',
    field: 'appScope',
    select: true,
    formatter: {
      type: 'dict',
      dictType: 'app_scope'
    }
  },
  {
    title: 'appKey',
    field: 'appKey',
  },
  {
    title: 'appSecret',
    field: 'appSecret',
  },
  {
    title: 'appTicket',
    field: 'appTicket',
  },
  {
    title: '操作',
    field: 'opt',
    width: 220,
    align: 'center',
    headerAlign: 'center',
    formatter: {
      type: 'opt'
    }
  },
];

/**
 *
 * @param active 执行的动作(edit,view,delete)
 */
function optColumnEvent(active: string, row: any) {
  switch (active) {
    case 'add': {
      proxy.$Modal.edit({
        title: '新增',
        comps: 'AppEdit',
        params: row,
        width: '650px',
        parentContext: proxy
      });
      break;
    }
    case 'edit': {
      proxy.$Modal.edit({
        title: '编辑',
        comps: 'AppEdit',
        params: row,
        width: '650px',
        parentContext: proxy
      });
      break;
    }
    case 'view': {
      proxy.$Modal.show({
        title: '详情',
        comps: 'AppEdit',
        params: row,
        width: '650px',
        parentContext: proxy
      });

      break;
    }
    case 'delete': {
      ElMessageBox.confirm(
          '您确定删除这条数据吗?',
          'Warning',
          {
            confirmButtonText: '删除',
            cancelButtonText: '取消',
            type: 'error',
            draggable: true,
            icon: markRaw(Delete),
          }
      ).then(() => {
        // @ts-ignore
        defaultTable.value.deleteTable('/user-center/app/delete', row.id);
      })
      break;
    }
  }
}

defineExpose({
  optColumnEvent
});
</script>
